//请求的底层
import axios from 'axios'
import { Message, MessageBox ,Notification } from 'element-ui'
// import store from '../store'
// import { getToken } from '@/utils/auth'

//创建axios实例
const service = axios.create({
  baseURL: ' https://www.easy-mock.com/mock/5c05370f23916949913b8c24', // api 的 base_url
  timeout: 5000 // 请求超时时间
})

// request拦截器
service.interceptors.request.use(
  config => {
    // if (store.getters.token) {
    //   config.headers['Auth'] = getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
    // }
    return config
  },
  error => {
    // Do something with request error
    console.log(error) // for debug
    Promise.reject(error)
  }
)



// response 拦截器
service.interceptors.response.use(
  response =>{
    // console.log(response)
    const detail = response.data.detail;
    if(detail.errMsg != 'ok'){
      Notification.error(detail.errMsg)
      return response.data
    }else{
      return response.data
    }
  },
  error => {
    console.log('err' + error) 
    return Promise.reject(error)
  }
)

export default service